home *** CD-ROM | disk | FTP | other *** search
/ Apple Developer Connection 1998 Fall: Game Toolkit / Disc.iso / Samples / Moofwars 1.02 / Tim's Libraries / Scaling.cp < prev    next >
Encoding:
Text File  |  1997-11-05  |  3.1 KB  |  99 lines  |  [TEXT/CWIE]

  1. /*************************************************************************************
  2. Scaling.cp
  3.  
  4. Scaling implements a standard 2D canvas to draw a set of TGraphics and tiles into.
  5. It also provides a set of globals that allow the sprite's location to be relative
  6. to a specific camera location.
  7.  
  8.  
  9. Author: Timothy Carroll
  10. Apple Developer Technical Support
  11. timc@apple.com
  12.  
  13. Modification History: 
  14. 2/27/97        TMC        Now properly includes error macros directly
  15. 1/23/97     TMC        Added include for Moofwars.h so that MrC will compile
  16. 8/15/96        TMC     Initial Release
  17.  
  18. Copyright © 1996, 1997 Apple Computer, Inc., All Rights Reserved
  19.  
  20. You may incorporate this sample code into your applications without
  21. restriction, though the sample code has been provided "AS IS" and the
  22. responsibility for its operation is 100% yours.  However, what you are
  23. not permitted to do is to redistribute the source as "DSC Sample Code"
  24. after having made changes. If you're going to re-distribute the source,
  25. we require that you make it clear in the source that the code was
  26. descended from Apple Sample Code, but that you've made changes.
  27. *************************************************************************************/
  28.  
  29.  
  30. #include "Scaling.h"
  31. #include "QDOffscreen.h"
  32. #include "Error Macros.h"
  33.  
  34. SInt32            gWorldCoordX = 0;
  35. SInt32            gWorldCoordY = 0;
  36. Rect            gClipRect = {0,0,0,0};
  37. SInt32            gClipCenterX = 0;
  38. SInt32            gClipCenterY = 0;
  39.  
  40. PixMapHandle    gDestPixMap = NULL;
  41. PixMapHandle    gBackPixMap = NULL;
  42. unsigned char    *gDestBaseAddr = NULL;
  43. unsigned char    *gBackBaseAddr = NULL;
  44. UInt32            gRowBytes;
  45.     
  46.  
  47.  
  48.  
  49.     
  50.  
  51.  
  52. /*************************************************************************************
  53.     SetDestinationBuffer
  54.     
  55.     This routine takes in the pix maps and sets up all the right variables for drawing.  Any
  56.     drawing using the TGraphic objects or TTiles must be done through a destination PixMap.
  57.     Ideally, if you are about to dispose of the buffers, you should call SetDestinationBuffer
  58.     with NULL for both pixmaps.  In the debugging version, this will cause an error if any
  59.     drawing is attempted through the NULL pix.
  60.     
  61.     If you specify a background pixmap, it must be the same dimensions, depth and rowbytes as
  62.     the main pix.
  63.  
  64. *************************************************************************************/
  65. void SetDestinationBuffer(PixMapHandle inDestPixMap, PixMapHandle inBackPixMap)
  66. {
  67.     // save the pix map info (so we can use it)
  68.     gDestPixMap = inDestPixMap;
  69.     gBackPixMap = inBackPixMap;
  70.  
  71.     // get info from the pix map
  72.     if (gDestPixMap != NULL)
  73.     {
  74.         gDestBaseAddr = ( unsigned char * ) GetPixBaseAddr( gDestPixMap );
  75.         gRowBytes = (*gDestPixMap )->rowBytes & 0x3fff;    
  76.     }
  77.     
  78.     if (gBackPixMap != NULL)
  79.         gBackBaseAddr = ( unsigned char * )GetPixBaseAddr (gBackPixMap );
  80.         
  81.     
  82. }
  83.  
  84.  
  85. void SetBufferClip(Rect *inClipRect)
  86. {
  87.     gClipRect = *inClipRect;
  88.     gClipCenterX  = (gClipRect.left + gClipRect.right) >> 1;
  89.     gClipCenterY  = (gClipRect.top  + gClipRect.bottom) >> 1;
  90. }
  91.  
  92.  
  93. // This function specifies the point in World Coordinates that coorsponds to the center
  94. // of the clipping rectangle.
  95. void SetWorldOrigin (SInt32 x, SInt32 y)
  96. {
  97.     gWorldCoordX = x;
  98.     gWorldCoordY = y;
  99. }